package src.io.bio;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Client2 {
    /*public static void main(String[] args) throws IOException {
        Socket socket=new Socket("localhost",9090);
        OutputStream outputStream=socket.getOutputStream();
        outputStream.write("服务器你好".getBytes("utf-8"));
        InputStream inputStream =socket.getInputStream();
        byte[] bytes=new byte[1024];


        while (inputStream.read(bytes)!=-1){
            System.out.println(new String(bytes,"utf-8"));
        }
    }*/
    /*public static void main(String[] args) {
        Socket socket;
        OutputStreamWriter out = null;
        InputStreamReader in=null;
        try {
             socket =new Socket("localhost",9999);
            out =new OutputStreamWriter(socket.getOutputStream());
            in =new InputStreamReader(socket.getInputStream());
            char [] c = new char[100];

            out.write("大大服务器");
            out.flush();
            while (in.read()!=-1){
                System.out.println(c);
            }
            Thread.sleep(1000);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if (out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }*/
    public static void main(String[] args) throws IOException, InterruptedException {
        BufferedReader in=null;
        PrintWriter out=null;
        try {
            Socket socket =new Socket("localhost",8888);
            in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(),true);
            /*while (in.read()!=-1){
                if (in.readLine()==null){
                    break;
                }
                System.out.println(in.readLine());
            }*/
            Thread.sleep(5000);
            out.println("---发送给服务器-服务器你好，我是客户");
//            Thread.sleep(10000L);
            System.out.println("-----接收到服务器----"+in.readLine());
            Thread.sleep(10000L);
           /* int a=200;
            while (a>100){
                Thread.sleep(100L);
                out.println("服务器你好，我是客户");
                a--;
            }
            while (a>10){
                Thread.sleep(100L);
                System.out.println(in.readLine());
                a--;
            }*/
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (out!=null){
                out.close();
            }
            if (in!=null){
                in.close();
            }
        }
    }
}
